#coding:utf-8
__author__ = '自之梦'

"""
@author:自之梦
@time: 17/5/25 上午10:26

#运单信息通知接口
"""
import xlrd
import csv
import os


def get_xls_Data(file_name="test.xlsx", sheet="sheet"):
    """获取xls文件内容,并以list形式返回"""
    if not os.path.exists(file_name):#判断文件是否存在
        return "errorCode: no results found for %s" % str(file_name)
    try:
        data = xlrd.open_workbook(file_name)
        table = data.sheet_by_name(sheet)
        rows = []
        a = []
        for i in range(1, table.nrows):#从第二行开始读取数
            rows.append(table.row_values(i))
        for i in rows:
            for x in i:
                a.append(x.encode("utf-8"))
        print a
        return rows
    except Exception as e:
        return e
    
def get_yaml_data():
    import yaml
    xml_Data = []
    new_xml_data = []
    f = open("2.yaml")
    x = yaml.load(f)
    for i in x:
        xml_Data.append(i.values())

    for i in xml_Data:
        t_len = len(i)
        for x in range(t_len):
            xml_val = i[x].strip().replace("\n", "").replace("\r", "")
            xml_val = xml_val.decode('GBK')
            xml_val=xml_val.strip().replace("\n", "").replace("\r", "")
            new_xml_data.append(xml_val)
    return new_xml_data

def get_csv_Data(file_name):
    if not os.path.exists(file_name):#判断文件是否存在
        return False
    rows = []
    with open(file_name, "rb") as f:
        readers = csv.reader(f)
        next(readers, None)
        for row in readers:
            rows.append(row)
    return rows


if __name__ == "__main__":
    print(get_xls_Data("crossboarder_portal_interface.xlsx", "alog_ordership_status_notify"))
    #print get_csv_Data("test1.csv")
    #print get_yaml_data()
    """
    t = get_yaml_data()
    for i in t:
        t_len = len(i)
        for x in range(t_len):
            xml_val = i[x].strip().replace("\n", "").replace("\r", "")
            print xml_val
    """
